import dash
from dash import html, dcc
from dash.dependencies import Input, Output, State
import feffery_antd_components as fac
import numpy as np

app = dash.Dash(
    __name__,
    external_scripts=[
        'https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js'
    ],
    update_title=None
)

app.layout = html.Div(
    [
        fac.AntdSpace(
            [
                fac.AntdStatistic(
                    id='statistic-value',
                    title='商品数',
                    value=13133
                ),
                fac.AntdStatistic(
                    id='statistic-value-incr',
                    title='较昨日',
                    value=1343,
                    valueStyle={
                        'color': '#cf1322'
                    },
                    prefix={
                        'mode': 'icon',
                        'content': 'antd-rise'
                    }
                ),
            ],
            align='center'
        ),
        dcc.Interval(
            id='statistic-interval-demo',
            n_intervals=0,
        )
    ]
)

# @app.callback(
#     [
#         Output('statistic-demo', 'value'),
#         Output('statistic-demo', 'suffix'),
#         Output('statistic-demo', 'valueStyle')
#     ],
#     Input('statistic-interval-demo', 'n_intervals'),
#     State('statistic-demo', 'value')
# )
# def statistic_demo_callback(n_intervals, value):
#     new_value = value + np.random.randn()
#     if new_value > value:
#         return [
#             new_value,
#             {
#                 'mode': 'text',
#                 'content': f'较昨日新增：{round(new_value-value, 2)}'
#             },
#             {
#                 'color': '#cf1322'
#             }
#         ]
#     return [
#         new_value,
#         {
#             'mode': 'text',
#             'content': f'较昨日减少：{round(new_value-value, 2)}'
#         },
#         {
#             'color': '#3f8600'
#         }
#     ]


if __name__ == '__main__':
    app.run_server(debug=True)
